/*******************************************************************************
 * Copyright (c) 2013 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package com.niannian.web;

import java.util.ArrayList;
import java.util.List;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import android.util.Log;
import com.niannian.db.MyDBUser;
import com.niannian.photo.Bimp;
import com.niannian.util.Common;
import com.niannian.util.UserInfoManager;
import com.niannian.util.network.NetRequest2;
import com.niannian.wxapi.WXEntryActivity;

/**
 * @author shengl
 * 
 */
public class nnSyncApi {

	private static MyDBUser userInfoManager = UserInfoManager.getUserInfoInstance();

	private static String scode = "0)7s+*yxa8ijrh3u7!y$^0#lv$kycl5!-hq0yp*wsx90oyt90n";

	private static void wrapauth(List<NameValuePair> parameters) {
		String uid = String.valueOf(userInfoManager.id);
		Log.i("uid————", uid);
		parameters.add(new BasicNameValuePair("uid", uid));
	}

	private static String wrapauth2(String url) {
		String uid = String.valueOf(userInfoManager.id);
		return url = url + uid;
	}

	private static void Addfamily(List<NameValuePair> parameters) {

		parameters.add(new BasicNameValuePair("fid", String.valueOf(userInfoManager.family)));
	}

	/*******************************************************
	 * 版本更新start
	 ******************************************************/

	public static String checkVersion() {
		String url = Common.domains("download/query_version");
		// String url = "http://api.dondon.im/download/query_version";
		List<NameValuePair> params = new ArrayList<NameValuePair>();
		// params.add(new BasicNameValuePair("new", "Y"));
		// params.add(new BasicNameValuePair("is_test_pkg", "Y"));// 取值:
		// 'Y'-是测试包,
		// 'N'或其他值-正式包.
		try {
			return new NetRequest2().syncRequest(url, "GET", params, null);
		} catch (Exception e) {
		}
		return null;
	}

	/*******************************************************
	 * 版本更新end
	 ******************************************************/
	public static String login(String usrname, String passwd) {
		String url = Common.domains("v1/auth/login");
		List<NameValuePair> params = new ArrayList<NameValuePair>();
		params.add(new BasicNameValuePair("username", usrname));
		params.add(new BasicNameValuePair("password", passwd));
		try {
			return new NetRequest2().syncRequest(url, "POST", params, null, true);
		} catch (Exception e) {
		}
		return null;
	}

	public static String checkVCode(String phone, String vcode, String action) {

		String url = Common.domains("v1/auth/check_code");
		// pack parameters into a list
		List<NameValuePair> params = new ArrayList<NameValuePair>();
		params.add(new BasicNameValuePair("phone", phone));
		params.add(new BasicNameValuePair("action", action));
		params.add(new BasicNameValuePair("vcode", vcode));

		try {
			return new NetRequest2().syncRequest(url, "POST", params, null);
		} catch (Exception e) {
		}

		return null;
	}

	public static String bind_phone(String phone, String vcode) {

		String url = Common.domains("v1/auth/bind_phone");
		List<NameValuePair> params = new ArrayList<NameValuePair>();
		params.add(new BasicNameValuePair("phone", phone));
		params.add(new BasicNameValuePair("vcode", vcode));

		try {
			return new NetRequest2().syncRequest(url, "POST", params, null);
		} catch (Exception e) {
		}

		return null;
	}

	public static String verifyPhone(String phone, String action) {
		String url = Common.domains("v1/auth/verify_phone");
		List<NameValuePair> params = new ArrayList<NameValuePair>();
		params.add(new BasicNameValuePair("phone", phone));
		params.add(new BasicNameValuePair("action", action));
		params.add(new BasicNameValuePair("scode", scode));
		try {
			return new NetRequest2().syncRequest(url, "POST", params, null);
		} catch (Exception e) {
		}
		return null;
	}

	public static String signup(String phone, String password1) {
		String url = Common.domains("v1/auth/signup");
		List<NameValuePair> params = new ArrayList<NameValuePair>();
		params.add(new BasicNameValuePair("username", phone));
		params.add(new BasicNameValuePair("password1", password1));

		try {
			return new NetRequest2().syncRequest(url, "POST", params, null);
		} catch (Exception e) {
		}
		return null;
	}

	public static String signup1(String phone, String password1, String vcode) {
		String url = Common.domains("v1/auth/signup1");
		List<NameValuePair> params = new ArrayList<NameValuePair>();
		params.add(new BasicNameValuePair("username", phone));
		params.add(new BasicNameValuePair("password1", password1));
		params.add(new BasicNameValuePair("vcode", vcode));

		try {
			return new NetRequest2().syncRequest(url, "POST", params, null, true);
		} catch (Exception e) {
		}
		return null;
	}

	public static String resetPassword(String phone, String password1, String vcode) {
		String url = Common.domains("v1/auth/reset_password");
		List<NameValuePair> params = new ArrayList<NameValuePair>();
		params.add(new BasicNameValuePair("phone", phone));
		params.add(new BasicNameValuePair("password1", password1));
		params.add(new BasicNameValuePair("vcode", vcode));

		try {
			return new NetRequest2().syncRequest(url, "POST", params, null);
		} catch (Exception e) {
		}
		return null;
	}

	public static String updateUserinfo(String nickname, String innername, String phone, String email, String gender, String avatar, String birth) {
		String url = Common.domains("v1/users/");
		url = wrapauth2(url);
		List<NameValuePair> params = new ArrayList<NameValuePair>();
		if (!Common.empty(nickname)) {
			params.add(new BasicNameValuePair("nickname", nickname));
		}
		if (!Common.empty(innername)) {
			params.add(new BasicNameValuePair("innername", innername));
		}
		if (!Common.empty(phone)) {
			params.add(new BasicNameValuePair("phone", phone));
		}

		if (!Common.empty(email)) {
			params.add(new BasicNameValuePair("email", email));
		}
		if (!Common.empty(gender)) {
			params.add(new BasicNameValuePair("gender", gender));
		}
		if (!Common.empty(birth)) {
			params.add(new BasicNameValuePair("birth", birth));
		}

		List<NameValuePair> files = new ArrayList<NameValuePair>();
		if (!Common.empty(avatar)) {
			files.add(new BasicNameValuePair("avatar", avatar));
		}
		try {
			return new NetRequest2().syncRequest(url, "PUT", params, files);
		} catch (Exception e) {
		}
		return null;
	}

	/**
	 * 发布一条家庭动态
	 * 
	 * @param info
	 *            文字内容
	 * @param pic
	 *            图片地址
	 * @param aud
	 *            语音地址
	 * @param aud_len
	 *            语音长度
	 * @return
	 */

	// public static String posts(String info, String pic, String aud, int
	// aud_len) {
	public static String posts(String info, List<NameValuePair> files, int aud_len) {
		String url = Common.domains("v1/posts");
		List<NameValuePair> params = new ArrayList<NameValuePair>();

		if (!Common.empty(info)) {
			params.add(new BasicNameValuePair("info", info));
		}
		if (!Common.empty(aud_len)) {
			params.add(new BasicNameValuePair("aud_len", String.valueOf(aud_len)));
		}
		if (Bimp.tempSelectBitmap.size() > 0) {
			params.add(new BasicNameValuePair("pic_num", Bimp.tempSelectBitmap.size() + ""));
		}
		Addfamily(params);

		// List<NameValuePair> files = new ArrayList<NameValuePair>();
		// if (!Common.empty(pic)) {
		// files.add(new BasicNameValuePair("pic", pic));
		// }
		// if (!Common.empty(aud)) {
		// files.add(new BasicNameValuePair("aud", aud));
		// }

		try {
			return new NetRequest2().syncRequest(url, "POST", params, files);
		} catch (Exception e) {
		}
		return null;
	}

	/**
	 * 得到家庭动态
	 * 
	 * @param created_time
	 *            动态创建时间
	 * @return
	 */
	public static String getposts(int created_time) {
		String url = Common.domains("v1/posts");
		List<NameValuePair> params = new ArrayList<NameValuePair>();
		if (created_time == 0) {
			params.add(new BasicNameValuePair("last_item_time", ""));
		} else {
			params.add(new BasicNameValuePair("last_item_time", Common.sgmdate2(created_time)));

		}

		Addfamily(params);
		try {
			return new NetRequest2().syncRequest(url, "GET", params, null);

		} catch (Exception e) {
		}
		return null;
	}

	public static String getMyPosts(int created_time) {
		String url = Common.domains("v1/posts");
		List<NameValuePair> params = new ArrayList<NameValuePair>();
		params.add(new BasicNameValuePair("q", "me"));
		if (created_time == 0) {
			params.add(new BasicNameValuePair("last_item_time", ""));
		} else {
			params.add(new BasicNameValuePair("last_item_time", Common.sgmdate2(created_time)));
		}
		try {
			return new NetRequest2().syncRequest(url, "GET", params, null);

		} catch (Exception e) {
		}
		return null;
	}

	public static String getOnePosts(int pid) {
		String url = Common.domains("v1/posts/" + pid);
		List<NameValuePair> params = new ArrayList<NameValuePair>();

		try {
			return new NetRequest2().syncRequest(url, "GET", params, null);

		} catch (Exception e) {
		}
		return null;
	}

	public static String addFamilyMember(String phone, String name) {
		String url = Common.domains("v1/families/" + String.valueOf(userInfoManager.family) + "/users");
		List<NameValuePair> params = new ArrayList<NameValuePair>();
		params.add(new BasicNameValuePair("phone", phone));
		params.add(new BasicNameValuePair("name", name));
		Addfamily(params);
		try {
			return new NetRequest2().syncRequest(url, "POST", params, null);
		} catch (Exception e) {
		}
		return null;
	}

	/**
	 * 得到一个家庭所有成员信息
	 * 
	 * @param userInfoManager
	 *            .family 家庭id
	 * 
	 * @return
	 */
	public static String getFamilyMember() {
		String url = Common.domains("v1/families/" + String.valueOf(userInfoManager.family) + "/users");
		try {
			return new NetRequest2().syncRequest(url, "GET", null, null);
		} catch (Exception e) {
		}
		return null;
	}

	/**
	 * 得到家庭成员一个用户的信息
	 * 
	 * @param uid
	 *            用户id
	 * @return
	 */
	public static String getFamilyMemberInfo(int uid) {
		String url = Common.domains("v1/families/" + String.valueOf(userInfoManager.family) + "/users/" + uid);
		try {
			return new NetRequest2().syncRequest(url, "GET", null, null);
		} catch (Exception e) {
		}
		return null;
	}

	public static String updateFamilyUserinfo(int uid, String nickname, String innername, String phone, String email, String gender, String avatar, String birth) {
		String url = Common.domains("v1/families/" + String.valueOf(userInfoManager.family) + "/users/" + uid);
		List<NameValuePair> params = new ArrayList<NameValuePair>();
		if (!Common.empty(nickname)) {
			params.add(new BasicNameValuePair("nickname", nickname));
		}
		if (!Common.empty(innername)) {
			params.add(new BasicNameValuePair("innername", innername));
		}
		if (!Common.empty(phone)) {
			params.add(new BasicNameValuePair("phone", phone));
		}

		if (!Common.empty(email)) {
			params.add(new BasicNameValuePair("email", email));
		}
		if (!Common.empty(gender)) {
			params.add(new BasicNameValuePair("gender", gender));
		}
		if (!Common.empty(birth)) {
			params.add(new BasicNameValuePair("birth", birth));
		}

		List<NameValuePair> files = new ArrayList<NameValuePair>();
		if (!Common.empty(avatar)) {
			files.add(new BasicNameValuePair("avatar", avatar));
		}
		try {
			return new NetRequest2().syncRequest(url, "PUT", params, files);
		} catch (Exception e) {
		}
		return null;
	}

	/**
	 * 反馈
	 * 
	 * @param content
	 *            反馈内容
	 * 
	 */

	public static String feedbacks(String content) {
		String url = Common.domains("v1/feedbacks");
		List<NameValuePair> params = new ArrayList<NameValuePair>();
		params.add(new BasicNameValuePair("content", content));
		try {
			return new NetRequest2().syncRequest(url, "POST", params, null);
		} catch (Exception e) {
		}
		return null;
	}

	/**
	 * 删除一条家庭动态
	 * 
	 * @param pid
	 *            动态id
	 * @return
	 */
	public static String deleteFamilyNews(String fid) {
		String url = Common.domains("v1/posts/" + fid);
		List<NameValuePair> params = new ArrayList<NameValuePair>();
		try {
			return new NetRequest2().syncRequest(url, "DELETE", params, null);
		} catch (Exception e) {
		}
		return null;
	}

	/**
	 * 删除家庭动态评论
	 * 
	 * @param fid
	 * @param cid
	 * @return
	 */
	public static String deleteFamilyNewsComment(String fid, String cid) {
		String url = Common.domains("v1/posts/" + fid + "/comments/" + cid);
		List<NameValuePair> params = new ArrayList<NameValuePair>();
		try {
			return new NetRequest2().syncRequest(url, "DELETE", params, null);
		} catch (Exception e) {
		}
		return null;
	}

	/**
	 * 拉取家庭最新动态数
	 * 
	 * @return
	 */
	public static String getFamilyNewsPostCount() {
		String url = Common.domains("v1/families/" + userInfoManager.family + "/new_messages_count");
		List<NameValuePair> params = new ArrayList<NameValuePair>();
		try {
			return new NetRequest2().syncRequest(url, "GET", params, null);
		} catch (Exception e) {
		}
		return null;
	}

	/*******************************************************
	 * 问候start
	 ******************************************************/

	/**
	 * 发布一条问候
	 * 
	 * @param rid
	 *            问候接收者id
	 * @param type
	 *            问候类型, 默认为S. 取值: S-简单语音, C-语音贺卡, M-音乐问候, R-问候回复
	 * @param info
	 *            文字内容
	 * @param pic
	 *            图片地址
	 * @param aud
	 *            语音地址
	 * @param aud_len
	 *            语音长度
	 * @param sent_time
	 *            问候发送时间
	 * @return
	 */
	public static String addRegard(int rid, String type, String info, String pic, String aud, int aud_len, String sent_time, String phone, String name,
			int reply_to) {
		String url = Common.domains("v1/regards/send");
		List<NameValuePair> params = new ArrayList<NameValuePair>();

		if (!Common.empty(type)) {
			params.add(new BasicNameValuePair("type", type));
		}
		if (!Common.empty(info)) {
			params.add(new BasicNameValuePair("info", info));
		}
		if (!Common.empty(aud_len)) {
			params.add(new BasicNameValuePair("aud_len", String.valueOf(aud_len)));
		}

		if (!Common.empty(sent_time)) {
			params.add(new BasicNameValuePair("sent_time", String.valueOf(sent_time)));
		}

		if (!Common.empty(phone)) {
			params.add(new BasicNameValuePair("phone", String.valueOf(phone)));
			params.add(new BasicNameValuePair("name", String.valueOf(name)));
		} else {
			params.add(new BasicNameValuePair("rid", String.valueOf(rid)));
		}

		// Addfamily(params);

		List<NameValuePair> files = new ArrayList<NameValuePair>();
		if (!Common.empty(pic)) {
			files.add(new BasicNameValuePair("pic", pic));
		}
		if (!Common.empty(aud)) {
			files.add(new BasicNameValuePair("aud", aud));
		}

		if (reply_to > 0) {
			params.add(new BasicNameValuePair("reply_to", reply_to + ""));
		}
		try {
			return new NetRequest2().syncRequest(url, "POST", params, files);
		} catch (Exception e) {
		}
		return null;
	}

	/**
	 * 获取问候信息
	 * 
	 * @param last_item_time
	 *            上一次请求数据列表中最后一条数据的发送时间
	 * @param limit_count
	 *            请求的数据条数, 默认10条
	 * @param rtype
	 *            问候数据类型, 取值: S-发送的问候, R-收到的问候
	 * 
	 */

	public static String getRegardList(int last_item_time, int limit_count, String rtype, int senderid) {
		String url = Common.domains("v1/regards");
		List<NameValuePair> params = new ArrayList<NameValuePair>();
		if (last_item_time == 0) {
			params.add(new BasicNameValuePair("last_item_time", ""));
		} else {
			params.add(new BasicNameValuePair("last_item_time", Common.sgmdate2(last_item_time)));
		}
		params.add(new BasicNameValuePair("limit_count", String.valueOf(limit_count)));
		params.add(new BasicNameValuePair("rtype", rtype));
		if (senderid != 0) {
			params.add(new BasicNameValuePair("sender", senderid + ""));
		}
		try {
			return new NetRequest2().syncRequest(url, "GET", params, null);
		} catch (Exception e) {
		}
		return null;
	}

	public static String getRegardList(int last_item_time, int senderid) {
		String url = Common.domains("v1/regards/received");
		List<NameValuePair> params = new ArrayList<NameValuePair>();
		if (last_item_time == 0) {
			params.add(new BasicNameValuePair("last_item_time", ""));
		} else {
			params.add(new BasicNameValuePair("last_item_time", Common.sgmdate2(last_item_time)));
		}

		if (senderid != 0) {
			params.add(new BasicNameValuePair("sender", senderid + ""));
		}
		try {
			return new NetRequest2().syncRequest(url, "GET", params, null);
		} catch (Exception e) {
		}
		return null;
	}

	public static String eidtRegard(int rid, String sent_time) {
		String url = Common.domains("v1/regards/" + rid);
		List<NameValuePair> params = new ArrayList<NameValuePair>();

		if (!Common.empty(sent_time)) {
			params.add(new BasicNameValuePair("sent_time", String.valueOf(sent_time)));
		}
		try {
			return new NetRequest2().syncRequest(url, "PUT", params, null);
		} catch (Exception e) {
		}
		return null;
	}

	public static String checkRegard(int id) {

		String url = Common.domains("v1/regards/" + String.valueOf(id) + "/check");
		try {
			return new NetRequest2().syncRequest(url, "PUT", null, null);
		} catch (Exception e) {
		}
		return null;
	}

	/*******************************************************
	 * 问候end
	 ******************************************************/

	/*******************************************************
	 * 提醒start
	 ******************************************************/
	/**
	 * 添加提醒
	 * 
	 * @param title
	 *            提醒名称
	 * @param spec_date
	 *            提醒日期
	 * @param desc
	 *            描述
	 * 
	 */

	public static String PushRegardsTip(int tid, String title, String spec_date, String setting, String desc) {
		String url = Common.domains("v1/regards/tips");
		List<NameValuePair> params = new ArrayList<NameValuePair>();
		if (tid > 0) {
			params.add(new BasicNameValuePair("tid", tid + ""));
		}

		params.add(new BasicNameValuePair("title", title));
		params.add(new BasicNameValuePair("spec_date", spec_date));
		params.add(new BasicNameValuePair("notice_type", setting));

		if (!Common.empty(desc)) {
			params.add(new BasicNameValuePair("desc", desc));
		}
		try {
			return new NetRequest2().syncRequest(url, "POST", params, null);
		} catch (Exception e) {
		}
		return null;
	}

	/**
	 * 
	 * @param last_item_time
	 *            问候提醒的最后一条时间
	 * @return
	 */
	public static String getRegardsTip(int last_item_time) {
		String url = Common.domains("v1/regards/tips");
		List<NameValuePair> params = new ArrayList<NameValuePair>();
		if (last_item_time == 0) {
			params.add(new BasicNameValuePair("last_item_time", ""));
		} else {
			params.add(new BasicNameValuePair("last_item_time", Common.sgmdate2(last_item_time)));
		}

		try {
			return new NetRequest2().syncRequest(url, "GET", params, null);
		} catch (Exception e) {
		}
		return null;
	}

	/**
	 * 删除一条提醒
	 * 
	 * @param pid
	 *            提醒id
	 * @return
	 */
	public static String deleteTip(String tid) {
		String url = Common.domains("v1/regards/tips/" + tid);
		List<NameValuePair> params = new ArrayList<NameValuePair>();
		try {
			return new NetRequest2().syncRequest(url, "DELETE", params, null);
		} catch (Exception e) {
		}
		return null;
	}

	public static String tipCheck(String tid) {
		String url = Common.domains("v1/regards/tips/" + tid + "/check");
		List<NameValuePair> params = new ArrayList<NameValuePair>();
		try {
			return new NetRequest2().syncRequest(url, "POST", params, null);
		} catch (Exception e) {
		}
		return null;
	}

	/*******************************************************
	 * 提醒end
	 ******************************************************/

	/**
	 * 创建家庭
	 * 
	 * @return
	 */
	public static String createFamily() {
		String url = Common.domains("v1/families");
		List<NameValuePair> params = new ArrayList<NameValuePair>();
		try {
			return new NetRequest2().syncRequest(url, "POST", params, null);
		} catch (Exception e) {
		}
		return null;
	}

	/**
	 * 移除家庭成员或者退出家庭
	 * 
	 * @param uid
	 *            用户ID
	 * @param type
	 *            0 表示 成员退出
	 * @return
	 */
	public static String deleteFamilyMenber(int uid, int type) {
		String url = Common.domains("v1/families/" + userInfoManager.family + "/users/" + uid);
		List<NameValuePair> params = new ArrayList<NameValuePair>();
		if (type == 0) {
			params.add(new BasicNameValuePair("q", "Y"));
		}
		try {
			return new NetRequest2().syncRequest(url, "DELETE", params, null);
		} catch (Exception e) {
		}
		return null;
	}

	/**
	 * 
	 * 解散家庭
	 * 
	 * @return
	 */
	public static String deleteFamily() {
		String url = Common.domains("v1/families/" + userInfoManager.family);
		List<NameValuePair> params = new ArrayList<NameValuePair>();

		try {
			return new NetRequest2().syncRequest(url, "DELETE", params, null);
		} catch (Exception e) {
		}
		return null;
	}

	/**
	 * 修改密码
	 * 
	 * @param password
	 *            原密码
	 * @param password1
	 *            新密码
	 * @return
	 */
	public static String changePassword(String password, String password1) {
		String url = Common.domains("v1/auth/change_password");
		List<NameValuePair> params = new ArrayList<NameValuePair>();

		params.add(new BasicNameValuePair("password", password));
		params.add(new BasicNameValuePair("password1", password1));

		try {
			return new NetRequest2().syncRequest(url, "POST", params, null);
		} catch (Exception e) {
		}
		return null;
	}

	/**
	 * 发布家庭评论
	 * 
	 * @param fid
	 * @param info
	 * @param aud
	 * @param aud_len
	 * @param reply_to
	 *            被评论人ID
	 * @return
	 */
	public static String FNComment(int fid, String info, String aud, int aud_len, int reply_to) {
		String url = Common.domains("v1/posts/" + fid + "/comments");
		List<NameValuePair> params = new ArrayList<NameValuePair>();

		params.add(new BasicNameValuePair("info", info));
		params.add(new BasicNameValuePair("aud_len", aud_len + ""));
		if (reply_to > 0) {
			params.add(new BasicNameValuePair("reply_to", reply_to + ""));
		}
		List<NameValuePair> files = new ArrayList<NameValuePair>();
		if (!Common.empty(aud)) {
			files.add(new BasicNameValuePair("aud", aud));
		}

		try {
			return new NetRequest2().syncRequest(url, "POST", params, files);
		} catch (Exception e) {
		}
		return null;
	}

	public static String deleteSendR(String rid) {
		String url = Common.domains("v1/regards/" + rid);
		List<NameValuePair> params = new ArrayList<NameValuePair>();
		try {
			return new NetRequest2().syncRequest(url, "DELETE", params, null);
		} catch (Exception e) {
		}
		return null;
	}

	/**
	 * 
	 * @param t
	 *            消息类型 1-新消息(未读), 0-历史消息(已读), 2-全部消息(包括已读和未读).
	 * @return
	 */
	public static String getNewsInfo(int time, int t) {
		String url = Common.domains("v1/posts/comments/rels");
		List<NameValuePair> params = new ArrayList<NameValuePair>();

		if (time == 0) {
			params.add(new BasicNameValuePair("last_item_time", ""));
		} else {
			params.add(new BasicNameValuePair("last_item_time", Common.sgmdate2(time)));
		}
		params.add(new BasicNameValuePair("t", t + ""));
		try {
			return new NetRequest2().syncRequest(url, "GET", params, null);
		} catch (Exception e) {
		}
		return null;
	}

	public static String getNewssInfo(int time) {
		String url = Common.domains("v1/regards/pull_messages");
		List<NameValuePair> params = new ArrayList<NameValuePair>();
		if (time == 0) {
			params.add(new BasicNameValuePair("last_item_time", ""));
		} else {
			params.add(new BasicNameValuePair("last_item_time", Common.sgmdate2(time)));

		}
		try {
			return new NetRequest2().syncRequest(url, "GET", params, null);
		} catch (Exception e) {
		}
		return null;
	}

	/**
	 * 得到系统消息列表
	 * 
	 * @param time
	 * @return
	 */
	public static String getSystemNewssInfo(int time) {
		String url = Common.domains("v1/regards/sys_messages");
		List<NameValuePair> params = new ArrayList<NameValuePair>();
		if (time == 0) {
			params.add(new BasicNameValuePair("last_item_time", ""));
		} else {
			params.add(new BasicNameValuePair("last_item_time", Common.sgmdate2(time)));

		}
		try {
			return new NetRequest2().syncRequest(url, "GET", params, null);
		} catch (Exception e) {
		}
		return null;
	}

	public static String getMembership(int uid, String phone) {

		String url = Common.domains("v1/families/" + userInfoManager.family + "/get_membership");
		List<NameValuePair> params = new ArrayList<NameValuePair>();
		// params.add(new BasicNameValuePair("uid", uid + ""));
		params.add(new BasicNameValuePair("phone", phone + ""));
		try {
			return new NetRequest2().syncRequest(url, "GET", params, null);
		} catch (Exception e) {
		}
		return null;
	}

	public static String WeixGetAccess_token(String code) {
		String url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=" + WXEntryActivity.APP_id + "&secret=" + WXEntryActivity.AppSecret + "&code="
				+ code + "&grant_type=authorization_code";
		List<NameValuePair> params = new ArrayList<NameValuePair>();
		try {
			return new NetRequest2().syncRequest(url, "GET", params, null);
		} catch (Exception e) {
		}
		return null;
	}

	public static String WeixGetUserinfo(String access_token, String openid) {
		String url = "https://api.weixin.qq.com/sns/userinfo?access_token=" + access_token + "&openid=" + openid;
		List<NameValuePair> params = new ArrayList<NameValuePair>();
		try {
			return new NetRequest2().syncRequest(url, "GET", params, null);
		} catch (Exception e) {
		}
		return null;
	}

	public static String WeixupdataUserinfo(String openid, String access_token, String open_name, String avatar_url, String refresh_token, String expires_in) {
		String url = Common.domains("v1/auth/open_login");
		List<NameValuePair> params = new ArrayList<NameValuePair>();

		params.add(new BasicNameValuePair("source_site", "weixin"));
		params.add(new BasicNameValuePair("openid", openid));
		params.add(new BasicNameValuePair("access_token", access_token));
		params.add(new BasicNameValuePair("open_name", open_name));
		params.add(new BasicNameValuePair("avatar_url", avatar_url));
		params.add(new BasicNameValuePair("refresh_token", refresh_token));
		params.add(new BasicNameValuePair("expires_in", expires_in));

		try {
			return new NetRequest2().syncRequest(url, "POST", params, null, true);
		} catch (Exception e) {
		}
		return null;
	}

}